﻿<?php
/**
 * @version		$Id: view.html.php 20196 2011-08-06 00:00:00Z jerome $
 * @package		Vsb.Site
 * @subpackage	com_geotrails
 * @copyright	Copyright (C) 2011 Verbier Technologies Sàrl, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
jimport('joomla.html.pane');
jimport('joomla.form.form');
jimport('joomla.application.component.view');
 
/**
 * HTML View class for the GeoTrails Component
 *
 * @package		Vsb.Site
 * @subpackage	com_geotrails
 * @since 1.7
 *
 */
 
class GeoTrailsViewGeoTrails extends JView {

	protected $gmap;
	protected $search_form;

	function display($tpl = null) {
	
		$application =& JFactory::getApplication();
		$pathway     =& $application->getPathway();

		$activityId = JRequest::getInt('activityId');
		
		if ($activityId) {
			$activity_text = JText::_('COM_GEOTRAILS_GEOTRAILS_VIEW_CB_ACTIVITE_'.$activityId);
		}
		
		// Génère le breadcrumb
		$pathway->addItem(JText::_('COM_GEOTRAILS_VIEW_GEOTRAILS_BC_LIST'), '');
		
		if (strlen($activity_text)) {
			$pathway->addItem($activity_text, '');
		}

		// Récupère les randonnées depuis le modèle
		$this->trails = $this->get('Trails');
		
		// Aucune randonnée trouvée
		if (!strlen($this->trails) || !count($this->trails)) {
			JFactory::getApplication()->enqueueMessage( JText::_('COM_GEOTRAILS_VIEW_ERROR_1') );
			return false;
		}
		
		// Récupère les paramètres de l'application
		$params = $application->getParams();
		
		// Récupère le code de langue, sur 2 positions
		$lang_code = $this->get('LanguageCode');
		
		// Récupère le titre de la rubrique menu
		$title   = $this->get('Title');
		$item_id = $this->get('ItemId');
		
		// Affichage de la carte sur la liste des fiches
		if ($params->get('show_map')) {
			$this->gmap = GeoTrailsModelGeoTrails::getGoogleMap($this->trails, $params->get('map_center'), $params->get('show_cluster'), $params->get('map_width'), $params->get('map_height'), $params->get('map_zoom'), $lang_code, $item_id);
		}
		
		// Récupération du formulaire de recherche
		if ($params->get('show_search_form')) {
			$this->search_form = JForm::getInstance('form_filter_list', JPATH_COMPONENT.'/models/forms/form_filter_list.xml');
		}

		if ($params->get('show_paginate')) {
			$session =& JFactory::getSession();
			$this->assignRef('paginate', $session->get("paginate_geotrails"));
		}		
		
		$this->assignRef('title',         $title);
		$this->assignRef('Itemid',        $item_id);
		$this->assignRef('params',        $params);
		$this->assignRef('activityId',    $activityId);
		$this->assignRef('activity_text', $activity_text);

		// Display the view
		parent::display($tpl);
	}
}